import { getMessage } from "../api/index.js"
import delay from "../utils/delay.js"
import bot from "../init/bot.js"
import {getDay,formatDate,parseTime} from "../utils/index.js"
const testId = '@@8869e66b76fc35f33c0da7974d11108822df5ee17fd9dbe637626436d1a35061'
export const nowTime = async ()=>{
    parseTime(new Date(), "{y}年{m}月{d}日 {a} {h}:{i}:{s}")
    const roomList= await bot.Room.findAll()
    console.log(roomList)
}
/**
 * 获取新闻
 */
export const getOneNews= async ()=>{
    const roomList= await bot.Room.findAll()
  console.log(roomList)
//    const room= roomList.find(it=>it.id==testId)
    try{
      
        const res = await getMessage({ msg: '今日热点新闻' ,token:500})
        let say = res.data.result.replace('以下是为你找到的热点新闻：','')
            say = say.replace(/参考来源.*$/,"")
            delay(100)
            const str = `今天是 ${ parseTime(new Date(), "{y}年{m}月{d}日 {a}")}\n\n当前时间:10:00:00\n\n今日热点新闻:` +say
            // room.say(str.trim())
           
            roomList.map(rooms=>{
                delay(1000)
                rooms.say(str.trim())
            })
    }catch(e){

    }
}
/**
 * 心跳检测 证明存在
 */
export const heartCheck = async ()=>{
    console.log('2小时一次心跳检测')
    
    const roomList= await bot.Room.findAll()
    console.log(roomList)
    const room= roomList.find(it=>it.id==testId)
    if(room){
        room.say('2小时一次心跳检测，证明我还活着')
    }
}
export const ClearMessage = async ()=>{
        const roomList= await bot.Room.findAll()
        roomList.map(item=>{
                item.messageList=[]
        })
}